// Ninf-G-XX, ver. 0.1
// Copyright 2011 National Institute of Advanced Industrial Science and Technology
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __NC_GRPC_DATA_H__
#define __NC_GRPC_DATA_H__

#include <vector>
#include <string>
#include <iostream>
#include "grpc_data.h"
#include "DataInputStream.hpp"
#include "DataOutputStream.hpp"
#include "URI.hpp"

namespace ninf {
namespace data {
class GrpcData {
  void writeMemoryDataTo(void * programBuffer, void ** ptr,  int * size);
  void readDataFrom(void * programBuffer, void * ptr, int size);

public:
  void * immediate;

  std::vector<ninf::lib::URI> inputURIs;
  std::vector<ninf::lib::URI> outputURIs;
  grpc_data_type_t variable_type;
  std::vector<int>    variable_configuration;
  std::vector<grpc_data_mode_t> storage_modes;

  /***
   * constructor for the GrpcHandle
   */
  GrpcData(
      const char ** list_of_URI_input,
      const char ** list_of_URI_output,
      grpc_data_type_t variable_type,
      const size_t  * variable_configuration,
      const grpc_data_mode_t * storage_mode);

  GrpcData():immediate(NULL){}
  GrpcData(const char * filename):immediate(NULL){readFrom(filename);}
  GrpcData(const std::string & filename):immediate(NULL){readFrom(filename.c_str());}

  GrpcData rfileMod(const std::string & in, const std::string & out);

  void writeTo(ninf::lib::DataOutputStream & dos);
  void readFrom(ninf::lib::DataInputStream & dis);
  void writeTo(const char * filename);
  void readFrom(const char * filename);

  void save(const char * url);
  void load(const char * url);

  void transfer(
    const char ** list_of_input_URI,
    const char ** list_of_output_URI,
    const grpc_data_mode_t * list_of_input_modes,
    const grpc_data_mode_t * list_of_output_modes);

  void * getLocalMemPointer();
  void * getLocalOutMemPointer();

  void update();

  grpc_error_t getInfo(
      grpc_data_info_type_t info_tag,
      const char * server_name,
      char ** info);

  friend std::ostream& operator<<(std::ostream& os, const GrpcData & data);
};


}
}



#endif
